package org.example.wework;

import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.By;

public class ContactPage extends BasePage{

    private final By addMember = By.id("ekp");
    private final By manual = By.xpath("//*[@text='手动输入添加']");
    private final By nameInput = By.id("ber");
    private final By phoneInput = By.id("gcr");
    private final By saveButton = By.xpath("//*[@text='保存']");
    private final By backButton = By.id("iwk");
    private final By closeButton = By.id("ix5");
    private By menu = By.id("ixb");

    By searchButton=By.id("com.tencent.wework:id/ixj");
    By editText=By.xpath("//android.widget.EditText");
    By searchResultList=By.id("com.tencent.wework:id/e4x");
    By infoButton=By.id("com.tencent.wework:id/ix5");
    By iconButton=By.id("i1v");
    By nameButton=By.id("ic4");
    By departText=By.id("bq_");

    public ContactPage(AppiumDriver driver) {
        super(driver);
    }

    public ContactPage add(String name,String phone) throws InterruptedException {
        find(menu).click().find(addMember).click().find(manual).click();
        find(nameInput).sendKeys(name);
        find(phoneInput).sendKeys(phone);
        find(saveButton).click();
        //todo: 用显式等待代替
        Thread.sleep(3000);
        find(backButton).click();
        find(closeButton).click();
        return this;
    }

    public Member find(String keyword){
        find(searchButton).click();
        find(editText).sendKeys(keyword);
        find(searchResultList).click();
        find(infoButton).click();
        find(iconButton).click();
        String name=find(nameButton).getText();
        String departName=find(departText).getText();

        driver.navigate().back();
        driver.navigate().back();
        return new Member(null,null);
    }


    public DefaultPage back() {
        return new DefaultPage(driver);
    }
}
